﻿using UtilsBase;
using UtilsORM;
using UtilsORM.MySql_IotGateway;
namespace GateWayCloodService.Data.TimeSeriesData
{
    public class TSDBIotDeviceValueLog
    {
        public async void writeDeviceValueLogAsync(string dguid, string key, string dvalue)
        {
            await Task.Run(() =>
            {
                string sql="";
                try
                {
                    if(!new DBTaosTDengineClient().DBisRun())
                    {//不启用
                        return;
                    }

                    iot_device device = new DBIotDeviceCache().getClientDeviceByCache(dguid);                   
                    string code = UtilsMachineInfo.getServerMachineCode();                                       
                    sql = " INSERT INTO tb_device_valuelog_" + device.d_id.ToString() + "_"+ code + " USING stb_device_valuelog TAGS(" + code + "," + device.d_id + ",'"+device.d_guid+"','"+device.d_model_guid+"') VALUES(NOW,'" + key + "','" + dvalue + "');";
                   // UtilsORM.DBTDengineClient client = new UtilsORM.DBTDengineClient();
                  //  client.ExecuteCommand(sql);

                }
                catch (Exception ex)
                {
                    Console.WriteLine("writeDeviceValueLog");
                    Console.WriteLine(sql);
                    Console.WriteLine(ex.ToString());
                }
            });
        }

      
    }
}
